<div class="page-header">
	<h2>Ajouter / Editer une brocante</h2>
</div>
<ol class="breadcrumb">
	<li><a href="<?php echo Router::url('admin'); ?>">Accueil</a></li>
	<li><a href="<?php echo Router::url('admin/brocantes'); ?>">Gestion des brocantes</a></li>
	<li class="active">Ajouter, Editer une brocante</li>
</ol>

<form class="form-horizontal" action="<?php echo Router::url('admin/brocantes/edit/'.$id); ?>" method="post" enctype="multipart/form-data">
	<div class="form-group">
		<div class="col-lg-10">
			<?php echo $this->Form->input('nom','Nom',array('type' => 'text', 'required' => '""')); ?>
		</div>
		<div class="col-lg-10">
			<?php echo $this->Form->input('slug','Adresse URL',array('type' => 'text', 'required' => '""')); ?>
		</div>
		<div class="col-lg-10">
			<?php echo $this->Form->input('lieu','Adresse de la brocante',array('type' => 'geolocalisation', 'required' => '""')); ?>
		</div>
		<div class="col-lg-5">
			<?php echo $this->Form->input('xLat',"Latitude de l'adresse",array('type' => 'text', 'required' => '""')); ?>
		</div>
		<div class="col-lg-5">
			<?php echo $this->Form->input('xLong',"Longitude de l'adresse",array('type' => 'text', 'required' => '""')); ?>
		</div>
		<div class="col-lg-5">
			<?php echo $this->Form->input('numDepartement','Département',array('type' => 'select', 'departements' => $departements)); ?>
		</div>
		<div class="col-lg-5">
			<?php echo $this->Form->input('dateBroc','Date et heure de la brocante',array('type' => 'datetimepicker', 'class' => 'inputdateBroc')); ?>
		</div>
		<?php echo $this->Form->input('id','hidden') ; ?>
		<div class="col-lg-10">
			<?php echo $this->Form->input('description','Description',array('type' => 'textarea', 'class' => 'form-control', 'class' => 'specifique', 'rows' => 5)); ?>
		</div>
		<div class="col-lg-10">
			<?php echo $this->Form->input('idCategorie','Catégorie',array('type' => 'select_categ', 'categories' => $categories)); ?>
		</div>
		<div class="col-lg-10">
			<?php echo $this->Form->input('online','En ligne',array('type' => 'checkbox')); ?>
		</div>
		<!-- img de la broc -->
		<div class="col-lg-5">	
			<?php echo $this->Form->input('fichier','Choisir une image',array('type' => 'file')); ?>
		</div>
		<div class="col-lg-5">	
			<img src="<?php echo Router::webroot('img/phBroc/'.$id.'.jpg'); ?>"  alt="img broc" width="100px" heigth="100px" />
		</div>
</div>
	<div class"actions">
		<a class="btn btn-default active" role="button" href="<?php echo Router::url('admin/brocantes/index'); ?>">Annuler</a>
		<input type="submit" class="btn btn-primary" value="Envoyer">
	</div>
</form>

<div id="element_to_pop_up_admin" style="text-align:center">
        <span class="button b-close"><span>X</span></span>
        <b>Géolocalisation<br>en cours ...</b><br><br>
        <img class="img-responsive center-block" src="<?php echo BASE_URL.'/webroot/img/gif/admin_loader.gif'; ?>" alt="Géolocalisation en cours ...">
</div>

<script src="<?php echo Router::webroot('js/jquery.min.js') ;?>"></script>
<script src="<?php echo Router::webroot('js/tinymce/tinymce.min.js') ;?>"></script>

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>
<script type="text/javascript">
$(function () {
	$('#inputdateBroc').datetimepicker({ language: 'fr'});
});

$(function() {
	$('#getCoord').click(function() {
		$().ready(function() {
			var bPopup = $('#element_to_pop_up_admin').bPopup({
				positionStyle: 'fixed', //'fixed' or 'absolute'
				speed: 650,
            	transition: 'slideIn',
	    		transitionClose: 'slideBack'
			}
				);
			var user1Location = $("#inputlieu").val();
			var geocoder = new google.maps.Geocoder();
        //convert location into longitude and latitude
        geocoder.geocode({
        	address: user1Location
        }, function(locResult) {
        	console.log(locResult);
        	var lat1 = locResult[0].geometry.location.lat();
        	var lng1 = locResult[0].geometry.location.lng();
        	//alert("latitude:" + lat1 + "<p>longitude:" + lng1 + "</p>");
        	$("#inputxLat").val(lat1);
        	$("#inputxLong").val(lng1);
        	//alert("sort");
        	bPopup.close();
        });
    });
	});

});
</script>

<script type="text/javascript">
tinymce.init({
	selector: "textarea.specifique",
	language : 'fr_FR',
	menubar : false,
	plugins: ["link", "image"],
	toolbar: [
	"undo redo | styleselect | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | link unlink"],
}); 

</script>